package com.zhangwei.expands.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zhangwei.expands.R;

/**
 * 下拉刷新 ListView
 * Adapter
 * LIst<Bean></>
 */
public abstract class BasePtrFragment extends BaseFragment implements AdapterView.OnItemClickListener {

    public ListView listView;
    private View empty;


    public int getLayoutid() {
        return R.layout.com_list_layout;
    }


    public View getHeadView() {
        return null;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutid(), container, false);
        return view;
    }

    @Nullable
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();


    }

    protected void initData() {

    }

    /**
     * @param view
     */
    private void initView(View view) {
        listView = (ListView) view.findViewById(R.id.com_ptr_id);
        empty = view.findViewById(R.id.empty_img);
        if (empty != null) {
            listView.setEmptyView(empty);
        }
        listView.setOnItemClickListener(this);
        if (getHeadView() != null) {
            listView.addFooterView(getHeadView());
        }


        setAdapter(listView);
    }

    public abstract void setAdapter(ListView listview);


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }
}
